project(third_serial CXX)

set(serial_SRCS
    src/serial.cc
    include/serial/serial.h
    include/serial/v8stdint.h
)

if(APPLE)
    # If OSX
    list(APPEND serial_SRCS src/impl/unix.cc)
    list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX)
    # If unix
    list(APPEND serial_SRCS src/impl/unix.cc)
    list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
else()
    # If windows
    list(APPEND serial_SRCS src/impl/win.cc)
    list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
endif()

if(APPLE)
    find_library(IOKIT_LIBRARY IOKit)
    find_library(FOUNDATION_LIBRARY Foundation)
endif()

add_library(sdkserial SHARED  ${serial_SRCS})

target_include_directories(sdkserial PUBLIC include)

if(APPLE)
    target_link_libraries(sdkserial ${IOKIT_LIBRARY} ${Foundation})
elseif(UNIX)
    target_link_libraries(sdkserial  pthread)
else()
    target_link_libraries(sdkserial setupapi)
endif()


#add_executable(serial_example examples/serial_example.cc)
#add_dependencies(serial_example serial)
#target_link_libraries(serial_example serial)


